<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div th:fragment="commonPerson">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="btn-group table-tool">
                <input type="text" placeholder="人员姓名/首拼" style="width:100px;"
                       class="table-tool-btn pull-left" id="person-name"/>
                <select id="person-tech" name="person-tech" class="form-control">

                </select>
               <!-- <input type="text" placeholder="技术" style="width:80px;"
                       class="table-tool-btn pull-left" id="person-tech"/>-->
                <input type="text" placeholder="位置" style="width:60px;"
                       class="table-tool-btn pull-left" id="person-loc"/>
                <button type="button" class="btn btn-outline btn-success btn-refresh" data-toggle="tooltip"
                        title="查询" id="btn-search-person">
                    <i class="fa fa-search" aria-hidden="true"></i>
                </button>
                <button type="button" class="btn btn-outline btn-success btn-refresh" data-toggle="tooltip"
                        title="重置" id="btn-reset-person">
                    <i class="fa fa-cog" aria-hidden="true"></i>
                </button>
                <button type="button" class="btn btn-outline btn-success btn-refresh" data-toggle="tooltip"
                        title="刷新" id="btn-refresh-person">
                    <i class="fa fa-refresh" aria-hidden="true"></i>
                </button>
            </div>
            <div class="btn-group table-tool pull-right table-time-filter" role="group">
                <button data-toggle="dropdown" class="btn btn-outline btn-success btn-refresh dropdown-toggle"
                        type="button">
                    <i class="fa fa-list-ul" aria-hidden="true"></i>
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">

                    <li class="dutyDurationLastWeek"><span>周执勤：</span><input type="text" onKeyUp="this.value=this.value.replace(/\D/g,'');"
                                                                             class="time-filter time-filter-start"> -
                        <input type="text" class="time-filter time-filter-end" onKeyUp="this.value=this.value.replace(/\D/g,'');">
                    </li>
                    <li class="dutyDurationLastMonth"><span>月执勤：</span><input type="text" onKeyUp="this.value=this.value.replace(/\D/g,'');"
                                                                              class="time-filter time-filter-start"> -
                        <input type="text" class="time-filter time-filter-end" onKeyUp="this.value=this.value.replace(/\D/g,'');">
                    </li>
                    <li class="flightDurationLastMonth"><span>月飞：</span><input type="text" onKeyUp="this.value=this.value.replace(/\D/g,'');"
                                                                               class="time-filter time-filter-start"> -
                        <input type="text" class="time-filter time-filter-end" onKeyUp="this.value=this.value.replace(/\D/g,'');">
                    </li>
                    <li class="flightDurationLastYear"><span>年飞：</span><input type="text" onKeyUp="this.value=this.value.replace(/\D/g,'');"
                                                                              class="time-filter time-filter-start"> -
                        <input type="text" class="time-filter time-filter-end" onKeyUp="this.value=this.value.replace(/\D/g,'');">
                    </li>
                    <li class="filter-btn pull-right">
                        <button class="btn btn-primary" type="button" id="btn-filter-person">筛选
                        </button>
                    </li>
                </ul>
            </div>
            <table id="table-person">
            </table>
        </div>
    </div>
    <script th:inline="javascript">
        $(function(){
            $.fn.select2.defaults.set("theme", "bootstrap"); //使用select2-bootstrap主题
            var typeData = getAjaxData({url: '/select2/getTechNoZ',data:{techType:'F'}});
            $("#person-tech").select2({
                minimumResultsForSearch: Infinity,
                data:typeData,
                width:120,
                allowClear:true,
                placeholder:'请选择技术'
            });
            $("#person-tech").val(null).trigger("change");
        });
        function initTablePerson() {
            $("#table-person").bootstrapTable("destroy").bootstrapTable({
                url: "/pilotAssign/listCrewInfoForAssign",
                clickToSelect: true,
                singleSelect: true,
                showRefresh: false,                  //是否显示刷新按钮
                striped: true,//行间隔色
                dataType:"json",
                locale: "${language}",
                classes: 'table table-hover table-condensed head-filter',
                uniqueId: 'workcode',
                height: docHeight * 0.75,
                queryParams: function (params) {
                    var result = {
                        flightDate: $("#flightDate").val(),
                        dutyCode:dutyCode
                    };
                    return result;
                },//传递参数
                columns: [
                    {
                        field: 'id',
                        title: '序号',
                        formatter: orderFormatter,
                        valign: 'middle',
                        align: 'center',
                        width: '40'
                    }, {
                        field: 'workcode',
                        title: '工号',
                        valign: 'middle',
                        align: 'center',
                        visible: false
                    }, {
                        field: 'cName',
                        title: '姓名',
                        valign: 'middle',
                        align: 'center',
                    }, {
                        field: 'pyAbbr',
                        title: '首拼',
                        visible: false
                    }, {
                        field: 'techZName',
                        title: '技术',
                        valign: 'middle',
                        align: 'center',
                    }, {
                        field: 'depName',
                        title: '部门',
                        valign: 'middle',
                        align: 'center',
                    }, {
                        field: 'sex',
                        title: '性别',
                        valign: 'middle',
                        align: 'center',
                        formatter: sexFormatter
                    }, {
                        field: 'age',
                        title: '年龄',
                        valign: 'middle',
                        align: 'center',
                        formatter:function(value, row, index){
                            var reg = /^[1-9]\d*$/;
                            if(reg.test(value)){
                                return value;
                            }else{
                                return '';
                            }
                        }
                    }, {
                        field: 'lastCityName',
                        title: '位置',
                        valign: 'middle',
                        align: 'center',
                    }, {
                        field: 'dutyDurationLastWeek',
                        title: '周执勤',
                        valign: 'middle',
                        align: 'center',
                        formatter: timeFormatter
                    }, {
                        field: 'dutyDurationLastMonth',
                        title: '月执勤',
                        valign: 'middle',
                        align: 'center',
                        formatter: timeFormatter
                    }, {
                        field: 'flightDurationLastMonth',
                        title: '月飞',
                        valign: 'middle',
                        align: 'center',
                        formatter: timeFormatter
                    }, {
                        field: 'flightDurationLastYear',
                        title: '年飞',
                        valign: 'middle',
                        align: 'center',
                        formatter: timeFormatter
                    }, {
                        field: 'techZLimit',
                        title: '限制',
                        valign: 'middle',
                        align: 'center',
                    }
                ],
                onClickRow: function (row, $element) {
                    $element.addClass('info').siblings().removeClass('info').end();
                    searchPersonByWorkcode(true, row.workcode, row.cName);
                },
                onDblClickRow:function (row, $element) {
                    //号位上添加人员
                    addPersonFromPersonList(row);
                },
                /* onSearch:function(text){
                     dragInit();
                 },*/
                onLoadSuccess: function (data) {
                    dragInit();
                    totalPerson = $("#table-person").bootstrapTable("getData");
                    /*//排班数据初始化
                    initTable();*/
                }
            });
        }

        //人员表格 tr drag初始化
        function dragInit() {
            $('#table-person tr').draggable({
                zIndex: 100,
                cursor: "move",
                cursorAt: {top: 10, left: 10},
                helper: function (event) {
                    var rowIndex = $(this).data("index");
                    var workcode = $(this).data("uniqueid");
                    var resultHTML = "";
                    if (workcode) {
                        var rowData = $('#table-person').bootstrapTable("getRowByUniqueId", workcode);
                        resultHTML += "<div class='ui-widget-header'>" +
                            "<span class='name'>" + rowData.cName + "</span>" +
                            "<span class='workcode'>" + workcode + "</span></div>";
                    }
                    return resultHTML;

                }
            });
        }

        function timeFormatter(value, row, index) {
            if (!value) {
                return '';
            } else {
                var hour = parseInt(value / 60) > 9 ? parseInt(value / 60) : '0' + parseInt(value / 60);
                var min = value % 60 > 9 ? value % 60 : '0' + (value % 60);
                var res = hour + ":" + min;
                return res;
            }

        }

        function rowFormatter(row, index) {
            if (row.ableFly) {
                return {
                    class: 'ableFly'
                }
            } else {
                return {
                    class: 'unableFly'
                }
            }
        }

        function techFormatter(value, row, index) {
            if (row.techZList[0]) {
                return row.techZList[0].techName;
            } else {
                return '';
            }

        }

        function searchPerson() {
            var name = $("#person-name").val();
            var tech = $.trim($("#person-tech option:selected").text());
            var loc = $("#person-loc").val();

            //dutyDurationLastWeek 周执勤
            var dutyDurationLastWeekStart = $(".dutyDurationLastWeek .time-filter-start").val();
            var dutyDurationLastWeekEnd = $(".dutyDurationLastWeek .time-filter-end").val();

            //dutyDurationLastMonth 月执勤
            var dutyDurationLastMonthStart = $(".dutyDurationLastMonth .time-filter-start").val();
            var dutyDurationLastMonthEnd = $(".dutyDurationLastMonth .time-filter-end").val();

            //flightDurationLastMonth 月飞
            var flightDurationLastMonthStart = $(".flightDurationLastMonth .time-filter-start").val();
            var flightDurationLastMonthEnd = $(".flightDurationLastMonth .time-filter-end").val();

            //flightDurationLastYear 年飞
            var flightDurationLastYearStart = $(".flightDurationLastYear .time-filter-start").val();
            var flightDurationLastYearEnd = $(".flightDurationLastYear .time-filter-end").val();
            var allPerson = totalPerson;
            if (allPerson) {
                var result = [];
                for (var i = 0; i < allPerson.length; i++) {
                    var optMatch = {
                        type: 'match',
                        param: [
                            {
                                key: 'cName,pyAbbr',
                                value: name
                            },
                            {
                                key: 'techZName',
                                value: tech
                            },
                            {
                                key: 'lastCityName',
                                value: loc
                            },
                        ]

                    }
                    var optRange = {
                        type: 'range',
                        param: [
                            {
                                key: 'dutyDurationLastWeek',
                                low: dutyDurationLastWeekStart,
                                high: dutyDurationLastWeekEnd
                            },
                            {
                                key: 'dutyDurationLastMonth',
                                low: dutyDurationLastMonthStart,
                                high: dutyDurationLastMonthEnd
                            },
                            {
                                key: 'flightDurationLastMonth',
                                low: flightDurationLastMonthStart,
                                high: flightDurationLastMonthEnd
                            },
                            {
                                key: 'flightDurationLastYear',
                                low: flightDurationLastYearStart,
                                high: flightDurationLastYearEnd
                            },
                        ]

                    }
                    if ($.doFilter(optMatch, allPerson[i]) && $.doFilter(optRange, allPerson[i])) {
                        result.push(allPerson[i]);
                    }
                }
                $("#table-person").bootstrapTable("load", result);
            }
        }

        function resetSearchPerson() {
            $("#person-name").val("");
            $("#person-tech").val(null).trigger("change");
            $("#person-loc").val("");
            $(".time-filter-start").val("");
            $(".time-filter-end").val("");
            $("#table-person").bootstrapTable("load", totalPerson);
        }

    </script>
</div>

</body>

</html>

